<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="gb2312"%>
<%@ page import="java.util.*"%>
<%@ page import="java.lang.Integer"%>
<%@ page import="parse.*"%>
<%@ page import="searchEngine.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>IT技术搜索引擎</title>
<style type="text/css">
.inf{
	font-family:Verdada,Arial,Helvetina,sans-serif font:14px;
}
.result{
	font-family:Verdada,Arial,Helvetina,sans-serif font:16px;
}
</style>
</head>
<body>
	<div>
		<table>
			<tr height="10"></tr>
			<tr>
				<th><font size="5" face="华文行楷" color="#ff7f50"> <a
						href="/explor/index">IT搜索引擎</a></font></th>
				<td>
					<form action="/explor/find" method="get">
						<input type="text" name="keys" size=50 style="height: 22px"
							maxlength="100"> 
							<input src="..\image\icon3.jpg"  type="image"  value="搜索"
							style="height: 27px;position: absolute">
					</form>
				</td>
			</tr>
		</table>
	</div>
	<div>
		<hr>
	</div>
	<div id="inf" class="inf" style="visibility: visible">
		<font face="Verdada">Loading...</font>
	</div>
	<div class="inf">
		<%
			String param = request.getParameter("keys");
			out.print("您提交的关键字：" + param + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");

			//用于存储结果总数
			int length = 0;
			WebInformation[] results = null;
			try {
				//获取搜索结果数组
				results = (WebInformation[]) request
						.getAttribute("webinformation");

				//数组长度
				length = results.length;
			} catch (Exception e) {
				e.printStackTrace();
				length = 0;
			}
			out.print("为您找到相关结果约" + length + "个");
		%>
	</div>
	<div>
		<h4>查询结果</h4>
	</div>
	<div id="result" class="result" style="visibility: hidden">
		<%
			//显示记录的启示记号
			int start = 1;
			//显示记录的终止记号
			int end = 0;
			if (length != 0) {
				//提取显示记录数，如果为空，表示从第一页显示
				if (request.getParameter("page") != null) {
					start = Integer.parseInt(request.getParameter("page"));
				}
				start = (start - 1) * 10;
				end = start + 10;

				if (end >= length) {
					end = length;
				}
				
				out.println("<table align='center' cellspacing='5' >");
				//从返回的查询结果中提取需要显示的部分
				for (int i = start; i < end; i++) {
					
					String keyWord=(String)request.getAttribute("keyWord");
					String k[]=keyWord.trim().split(" ");
					String Summary=results[i].getContent();
					int leng=k.length;
					for(int j=0;j<leng;j++)
					{
						int kstart=0;
						int kend=0;
						kstart=Summary.indexOf(k[j])-1;
						kend=kstart+k[j].length();
						if (kend >= 70)
							kend = 70;
						if (kstart > 0) {
							if (kstart - 10 > 0)
								Summary = Summary.substring(0, kstart - 10)
										+ "......" + "<font color=\"#FF0000\">"
										+ k[j] + "</font>"
										+ Summary.substring(kend) + "......";
							else
								Summary = "......" + "<font color=\"#FF0000\">"
										+ k[j] + "</font>"
										+ Summary.substring(kend) + "......";
						}
					}
					out.print("<tr>");
					out.print("<font color=\"#0033cc\">");
		%>
		<jsp:text>
			<![CDATA[<a href="]]>
		</jsp:text>
		<jsp:expression>results[i].getURL()</jsp:expression>
		<jsp:text>
			<![CDATA[">]]>
		</jsp:text>
		<jsp:expression>results[i].getTitle()</jsp:expression>
		<jsp:text>
			<![CDATA[</a>]]>
		</jsp:text>

		<%
			out.print("</font><br>");
					out.print("<font color=\"#008000\">"
							+ Summary+ "</font><br/>");
					out.print("<a href=" + results[i].getURL() + ">"
							+ "<font color=\"#CCCCCC\">" + results[i].getURL()
							+ "</font>" + "</a><br/><br/>");
					out.print("</tr>");
				}
			}
			out.println("</table>");
		%>
	</div>
	<div id="page">
		<%
			if (length != 0) {
				int j = 0;
				if (start > 20)
					j = start - 20;
				//显示页数导航栏
				out.print("<a href=\"/explor/find?keys=" + param + "&page=" + 1
						+ "\">" + "首页</a>&nbsp;");
				for (int k = 0; j <= length && k < 20; j += 10, k++) {
					out.print("<a href=\"/explor/find?keys=" + param + "&page="
							+ (j / 10 + 1) + "\">[" + (j / 10 + 1)
							+ "]</a>&nbsp;");
				}
			}
		%>
	</div>
	<br />
	<br />
	<br />
	<%--显示结果 --%>
	<script type="text/javascript">
		document.getElementById("inf").style.visibility = "hidden";
		document.getElementById("result").style.visibility = "visible";
	</script>
</body>
</html>